package com.cloudservice.ccs.biz.impl;

import com.cloudservice.ccs.biz.ICustomerInfoBiz;
import com.cloudservice.ccs.entity.CustomerInfo;
import com.cloudservice.ccs.exception.CommonWordException;
import com.cloudservice.ccs.exception.CustomerInfoException;
import com.cloudservice.ccs.mapper.CustomerInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CustomerInfoImpl implements ICustomerInfoBiz {
    @Autowired
    private CustomerInfoMapper customerInfoMapper;
    @Override
    public void save(CustomerInfo customerInfo) {
        int result = customerInfoMapper.save(customerInfo);
        if (result == 0) {
            throw new CustomerInfoException("Create CustomerInfo entity error");
        }
    }

    @Override
    public void partialUpdate(Integer id, Map<String, Object> fields) {
        int result = customerInfoMapper.partialUpdate(id, fields);
        if (result == 0) {
            throw new CustomerInfoException("Update CustomerInfo entity error");
        }
    }

    @Override
    public void update(Integer id, CustomerInfo customerInfo) {
        int result = customerInfoMapper.update(id, customerInfo);
        if (result == 0) {
            throw new CustomerInfoException("Update CustomerInfo entity error");
        }
    }

    @Override
    public void delete(Integer id) {
        int result = customerInfoMapper.delete(id);
        if (result == 0) {
            throw new CustomerInfoException("Delete CustomerInfo entity error");
        }
    }

    @Override
    public CustomerInfo getOne(Integer id) {
        CustomerInfo customerInfo = customerInfoMapper.getOne(id);
        if (customerInfo == null) {
            throw new CustomerInfoException("Get CustomerInfo entity error: no such entity");
        }
        return customerInfo;
    }

    @Override
    public List<CustomerInfo> getAll() {
        return customerInfoMapper.getAll();
    }

    @Override
    public List<CustomerInfo> conditionQuery(Map<String,Object> fields){
        List<CustomerInfo> result = customerInfoMapper.conditionQuery(fields);
        if (result==null) {
            throw new CustomerInfoException("访客条件查询发生错误");
        }
        return result;
    }
}
